﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoVanHocTapData.Entities;
using CoVanHocTapData.Infrastructure;

namespace CoVanHocTapData.Concretes
{
    public class NganhDaoTaoRepository : INganhRepository
    {
        DangKyPhuEntities entities;
        
        public NganhDaoTaoRepository()
        {
            entities = new DangKyPhuEntities();
        }

        #region Repository
        SinhVienRepository sinhVienRepo = new SinhVienRepository();
        #endregion

        #region INganhRepository Members

        public IQueryable<NganhDaoTao> LayNganhDaoTao()
        {
            return (from m in entities.NganhDaoTaos
                    select m);
        }

        public IQueryable<NganhDaoTao> LayNganhDaoTao(string KhoaID)
        {
            return (from m in entities.NganhDaoTaos
                    where m.Khoa.KhoaID.Equals(KhoaID)
                    select m);
        }

        public IQueryable<NganhDaoTao> LayNganhDaoTaoTheoNganh(string nganhID)
        {
            return (from m in entities.NganhDaoTaos
                    where m.NganhID.Equals(nganhID)
                    select m);
        }


        public string LayMaNganh(string LopID)
        {
            return (from m in entities.Lops
                    where m.LopID.Equals(LopID)
                    select m.NganhDaoTao.NganhID).ToList().FirstOrDefault();
        }

        public NganhDaoTao LayNganhTuMaSV(string maSV)
        {
            SinhVien sinhVien = sinhVienRepo.LaySVTuMaSV(maSV);            
            return (from m in entities.NganhDaoTaos
                    where m.NganhID == sinhVien.Lop.NganhID
                    select m).FirstOrDefault();
        }

        #endregion
    }
}
